libxenlight: do not try to set memory target with a number we haven't
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 12 Jan 2010 07:03:14 +0000 (07:03 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 12 Jan 2010 07:03:14 +0000 (07:03 +0000)
verified in set-mem.

checking that memory string conversion what done properly instead of
sending a request to balloon a domain to 0 memory.

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
tools/libxl/xl.c

index 2322ce4a67e3ff909cf0738b1031f54c36f8ad9c..90896f3e087285dccc540202902ea27de6c5aa63 100644 (file)
@@ -993,6 +993,8 @@ void set_memory_target(char *p, char *mem)
 {
     struct libxl_ctx ctx;
     uint32_t domid;
+    uint32_t memorykb;
+    char *endptr;
 
     if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
         fprintf(stderr, "cannot init xl context\n");
@@ -1004,7 +1006,13 @@ void set_memory_target(char *p, char *mem)
         fprintf(stderr, "%s is an invalid domain identifier\n", p);
         exit(2);
     }
-    libxl_set_memory_target(&ctx, domid, atoi(mem));
+    memorykb = strtoul(mem, &endptr, 10);
+    if (*endptr != '\0') {
+        fprintf(stderr, "invalid memory size: %s\n", mem);
+        exit(3);
+    }
+    printf("setting domid %d memory to : %d\n", domid, memorykb);
+    libxl_set_memory_target(&ctx, domid, memorykb);
 }
 
 int main_memset(int argc, char **argv)